package libs;

import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 *  Class for sorting Student collections
 * @author Dejvino
 */
public class StudentSorter {
    Set<Student> set;
    public StudentSorter(Set<Student> students) {
        this.set = students;
    }

    public Set<Student> getSet() {
        return set;
    }

    public List<Student> getList() {
        if(set == null)
            return null;
        if(set.isEmpty())
            return null;
        LinkedList list = new LinkedList(set);
        java.util.Collections.sort(list, new Comparator<Student>(){
            public int compare(Student s1, Student s2) {
                return s1.getId() - s2.getId();
            }
        });
        return list;
    }

    public Student[] getArray() {
        List<Student> list = getList();
        if(list == null || list.isEmpty())
            return null;
        return (Student[])list.toArray(new Student[list.size()]);
    }
}
